package org.devocean.groupbuying.web.frontend.displaybeans;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.devocean.groupbuying.domain.Article;
import org.devocean.groupbuying.domain.Customer;
import org.devocean.groupbuying.domain.Product;
import org.devocean.groupbuying.domain.Purchase;
import org.devocean.groupbuying.domain.PurchaseItem;

public class PurchaseBean {

	private Customer customer;
	private Purchase purchase;
	private Map<String, PurchaseItem> purchaseItems = new HashMap<String, PurchaseItem>();
	private String mediaFilePath;
	private String title;
	private String description;
	private Double amount;
	

	public PurchaseBean(Purchase purchase) {
		this.customer = purchase.getCustomer();
		this.setAmount(purchase.getAmount());
		System.out.println("amount : " +purchase.getAmount());
		Iterator<PurchaseItem> iterator = purchase.getItems().iterator();
		final Product product = iterator.next().getDiscount().getDeal()
				.getProduct();
		this.mediaFilePath = product.getArticlesLocalization()
				.getMediaLocalizations().iterator().next().getMediaFilePath();
		
		Article article = product.getArticlesLocalization().getArticles().iterator()
				.next();
		this.title = article.getTitle();
		
		this.setDescription(article.getBody());
		for (PurchaseItem item : purchase.getItems()) {
			purchaseItems.put(item.getDiscount().getFormula().getPlan()
					.getArticlesLocalization().getArticles().iterator().next()
					.getTitle(), item);
		}

	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public Purchase getPurchase() {
		return purchase;
	}

	public void setPurchase(Purchase purchase) {
		this.purchase = purchase;
	}

	public Map<String, PurchaseItem> getPurchaseItems() {
		return purchaseItems;
	}

	public void setPurchaseItems(Map<String, PurchaseItem> purchaseItems) {
		this.purchaseItems = purchaseItems;
	}

	public String getMediaFilePath() {
		return mediaFilePath;
	}

	public void setMediaFilePath(String mediaFilePath) {
		this.mediaFilePath = mediaFilePath;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Double getAmount() {
		return amount;
	}

	public void setAmount(Double amount) {
		this.amount = amount;
	}

	
}
